/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @file TestDbus.c
* 
* Library for testing the dbus library code.
* 
* @author Miguel Ángel Vílchez López 2008 <sacra@openmatica.es>
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <dbus.cpp>

/**
* @example TestDbus.c
*/

int main(int argc, char *argv[])
{

	if(argc<2)
	{
		puts("\nUSE:\nTestDbus <type>\n");
		puts("types:");
		puts("\tsend <name> <signal> <data>");
		puts("\trecv <name> <signal>\n");
		puts("\t  e.g.");
		puts("\t    TestDbus send test testing \"something to send\" => Sends \"something\" to test/testing.");
		puts("\t    TestDbus recv test testing => Waits to receive something on test/testing\n");

		exit(EXIT_SUCCESS);
	}


	if(strcmp(argv[1],"recv")==0)
	{
		char* buffer=(char*)malloc(100*sizeof(char));
		CMDbus conexion(argv[2],argv[3]);
		conexion.ruleSignal();
		printf("Waiting signal...\n");
		int a=0;
		while(a<1)
			a=conexion.recvSignal(buffer);

		printf("Number of characters received:\t%d\nReceived:\t%s\n",a,buffer);
		free(buffer);
	}

	if(strcmp(argv[1],"send")==0)
	{
		CMDbus conexion(argv[2],argv[3]);
		conexion.sendSignal(argv[4]);
	}
	
}
